<?php
namespace app\admin\model;

use think\Model;
use app\admin\model\Channel;

class BusSellingCost extends Model
{
    public function getListAll($request)
    {
        $data = $this->alias('bsc')
        ->field('bsc.*, concat( bus_channel.channel_id , "/", bus_channel.company_name ) as company_name,adm_user.name,adm_user.username')
        ->join('adm_user','bsc.user_id = adm_user.id')
        ->join('bus_channel','bsc.channel_id = bus_channel.channel_id');

        switch (session('user_type')) {
            case 'admin':
                # code...
                break;
            case 'clerk':
                $data = $data->where('bsc.user_id',session('user_id'));
                break;

            default:
                exit;
                break;
        }

        $data = $data->order('status,bsc.channel_id desc')
        ->paginate($request['limit'])
        ->toarray();

        foreach ($data['data'] as $key => $value) {
            $data['data'][$key]['name'] = $value['name'] . '(' . $value['username'];
        //     switch ($value['status']) {
        //         case '0':
        //             $data['data'][$key]['status'] = '待审核';
        //             break;
        //         case '1':
        //             $data['data'][$key]['status'] = '通过';
        //             break;
        //         case '2':
        //             $data['data'][$key]['status'] = '拒绝';
        //             break;

        //         default:
        //             # code...
        //             break;
        //     }
        //     switch ($value['type']) {
        //         case '1':
        //             $data['data'][$key]['type'] = '加款';
        //             break;
        //         case '2':
        //             $data['data'][$key]['type'] = '减款';
        //             break;
        //     }
        }

        return $data;

    }
}